var ymus_httpurl = '';
if(typeof(ymus_auto_load) === 'undefined'	){ymus_auto_load = true;}

ymus_min = function() {
	var scripts = [],
		loading = false;
	
	function init() {
		var list = document.getElementsByTagName("script");
		for ( var i = 0; i < list.length; i++) {
			if (list[i].src && list[i].src.indexOf('ymus_min.js') != -1) {
				minfile = list[i].src;
				var tmp = minfile.split('ymus_min.js');
				ymus_httpurl = tmp[0];
				break;
			}
		}
		/*
		 * always Makt ymus_track First because we use it in ymus_main
		 */
		ymus_min.loadScript(ymus_httpurl + 'ymus_track.js?rn=' + Math.random());
		ymus_min.loadScript(ymus_httpurl + 'ymus_main.js?rn=' + Math.random());
		
	}
	function loadScript(src) {
		scripts.push(src);
		jsnode();
	}
	function jsnode() {
		if (!scripts.length || loading) return false;
		var src = scripts.shift();
		var headTag = document.getElementsByTagName("HEAD")[0];
		var tag = document.createElement("script");
		tag.type = "text/javascript";
		tag.src = src;
		var loadFn = function() {
			loading = false;
			if (scripts.length)
				jsnode();
		};
		add_event(tag, 'load', loadFn, false);
		tag.onreadystatechange = function() {
			if (tag.readyState == 'loaded') {
				loadFn();
			}
		};
		headTag.appendChild(tag);
		loading = true;
	}

	function add_event(elm, evType, fn, useCapture) {
		if (elm.addEventListener) {
			elm.addEventListener(evType, fn, useCapture);
			return true;
		} else if (elm.attachEvent) {
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		} else {
			elm['on' + evType] = fn;
		}
	}

	return {
		init : init,
		jsnode : jsnode,
		add_event : add_event,
		loadScript : loadScript
	}

}();

if(ymus_auto_load){
	ymus_min.add_event(window, 'load', ymus_min.init, false);
}